//
//  MultiTouchSprite.m
//  iSudoku
//
//  Created by acumen on 5/27/13.
//  Copyright 2013 Tri Vo. All rights reserved.
//

#import "MultiTouchSprite.h"


@implementation MultiTouchSprite

- (void)onEnter {
    [[[CCDirector sharedDirector] touchDispatcher] addStandardDelegate:self priority:0];
    [super onEnter];
}

- (void)onExit {
    [[[CCDirector sharedDirector] touchDispatcher] removeDelegate:self];
    [super onExit];
}

- (BOOL) touched:(UITouch *)touch {
    CGPoint touchPoint = [touch locationInView:touch.view];
    touchPoint = [[CCDirector sharedDirector] convertToGL:touchPoint];
    CGRect rect = [self boundingBox];
    if(CGRectContainsPoint(rect, touchPoint)) {
        return YES;
    }
    return NO;
}

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    NSSet *allTouches = [event allTouches];
    for (UITouch *touch in allTouches) {
        BOOL isTouched = [self touched:touch];
        if(isTouched) {
            id enlarge = [CCScaleTo actionWithDuration:0.5f scale:1.1f];
            id resize = [CCScaleTo actionWithDuration:0.5f scale:1];
            [self runAction:[CCSequence actions:enlarge, resize, nil]];
        }
    }
}

@end
